package com.hjm.admin.moule.db.helpter;

import android.database.sqlite.SQLiteDatabase;

import com.hjm.admin.moule.MyApp;
import com.hjm.admin.moule.db.gen.DaoMaster;
import com.hjm.admin.moule.db.gen.DaoSession;

public class DaoDbHelper {
    private static final String DB_NAME = "WeYueReader_DB";
    private static volatile DaoDbHelper sInstance;
    private SQLiteDatabase mDb;
    private DaoMaster mDaoMaser;
    private DaoSession mSession;

    private DaoDbHelper() {
        DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(MyApp.getAppContext(), DB_NAME);
        mDb = openHelper.getWritableDatabase();
        mDaoMaser = new DaoMaster(mDb);
        mSession = mDaoMaser.newSession();
    }

    public static DaoDbHelper getInstance() {
        if (sInstance == null) {
            synchronized (DaoDbHelper.class) {
                if (sInstance == null) {
                    sInstance = new DaoDbHelper();
                }
            }
        }
        return sInstance;
    }

    public DaoSession getSession() {
        return mSession;
    }

    public SQLiteDatabase getDb() {
        return mDb;
    }

    public DaoSession getNewSession() {
        return mDaoMaser.newSession();
    }
}
